trigger InviteeTrigger on MeetingInvitees__c (before insert, before update) {

	Map<String, Id> uIds = new Map<String, Id>();
	Map<String, Id> cIds = new Map<String, Id>();
	Map<String, Id> lIds = new Map<String, Id>();
	
	for (MeetingInvitees__c mi : trigger.new) {
		if (mi.User__c != null) {
			uIds.put(mi.User__c, mi.User__c);
		} else if (mi.Lead__c != null) {
			lIds.put(mi.Lead__c, mi.Lead__c);
		} else if (mi.Contact__c != null) {
			cIds.put(mi.Contact__c, mi.Contact__c);
		}
	}
	
	Map<Id, User> uEm = new Map<Id, User>([Select Id, Email From User Where Id In :uIds.keySet()]);
	Map<Id, Contact> cEm = new Map<Id, Contact>([Select Id, Email From Contact Where Id In :cIds.keySet()]);
	Map<Id, Lead> lEm = new Map<Id, Lead>([Select Id, Email From Lead Where Id In :lIds.keySet()]);

	for (MeetingInvitees__c mi : trigger.new) {
		if (mi.User__c != null) {
			mi.Email__c = uEm.get(mi.User__c).Email;
			mi.LinkId__c = mi.User__c;
		} else if (mi.Lead__c != null) {
			mi.Email__c = lEm.get(mi.Lead__c).Email;
			mi.LinkId__c = mi.Lead__c;
		} else if (mi.Contact__c != null) {
			mi.Email__c = cEm.get(mi.Contact__c).Email;
			mi.LinkId__c = mi.Contact__c;
		}
	}
	
}